package com.shiliao.app.activity.index.presenter;

import android.text.TextUtils;

import com.shiliao.app.activity.index.entity.AddRemindEntity;
import com.shiliao.app.activity.index.service.IDailyRemindersService;
import com.shiliao.app.activity.index.service.impl.DailyRemindersImpl;
import com.shiliao.app.activity.index.view.DailyRemindersView;
import com.shiliao.app.utils.YMServerUtil;
import com.yimei.framework.mvp.presenter.IBasePresenter;
import com.yimei.framework.network.ICallBack;
import com.yimei.framework.util.LogUtil;
import com.yimei.framework.util.ParseHelper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by yinzhiqiang on 2017/10/9.
 */

public class DailyRemindersPresenter extends IBasePresenter {
    private DailyRemindersView dailyRemindersView;
    private IDailyRemindersService dailyRemindersService;

    public DailyRemindersPresenter(DailyRemindersView dailyRemindersView) {
        this.dailyRemindersView = dailyRemindersView;
        dailyRemindersService=new DailyRemindersImpl();
        setService(dailyRemindersService);
    }

    public void requestRemindList(String userId){//获取文章对应的日常提醒
        Map map=new HashMap();
        if (!TextUtils.isEmpty(userId)){
            map.put("user_id",userId);
        }
        dailyRemindersService.requestRemindList(YMServerUtil.ACTION_GET_REMIND_LIST, map, new ICallBack() {
            @Override
            public void onSuccess(int statusCode, Object result) {
                List<AddRemindEntity> list= ParseHelper.getModelList(result.toString(),"reminder_array", AddRemindEntity.class);
                dailyRemindersView.setAdapter(list);
                LogUtil.e("yzq",result.toString());
            }

            @Override
            public void onFail(int statusCode, Object result) {

            }
        });
    }

    public void requestDeteleRemind(String reminderId, final String userId){//删除日常提醒
        LogUtil.e("yzq",reminderId+"..."+userId);
            Map map=new HashMap();
        if (!TextUtils.isEmpty(reminderId)){
            map.put("user_id",userId);
        }
        if (!TextUtils.isEmpty(userId)){
            map.put("reminder_id",reminderId);
        }
            dailyRemindersService.requestDeteleRemind(YMServerUtil.ACTION_DETELE_REMIND, map, new ICallBack() {
                @Override
                public void onSuccess(int statusCode, Object result) {
                    LogUtil.e("yzq",result.toString()+"+=========");
                    //requestRemindList(userId);
                    dailyRemindersView.delectSuccess();
                }

                @Override
                public void onFail(int statusCode, Object result) {
                    LogUtil.e("yzq",result.toString()+"+=========");
                }
            });
    }
}
